package algorithm.quartile;

import java.util.List;
import java.util.Vector;

import util.VectorMath;

import algorithm.RADDACL_Cluster;
import algorithm.Region;

/**
 * This class represents a set of points in space of n-dimensions in the RAADACL cluster.<BR><BR>
 * 
 * To determine if this is a Pre-Cluster, this algorithm uses Quartiles to establish
 * a threshold.
 * 
 * @author Dan Avila
 *
 */
public class Region_Quartile extends Region
{
	private DistanceTable_Centroid table;
	private Double pthreshold;
	private Vector<Double> pcentroid;
	/**
	 * 
	 * @param parent
	 * @param inputIndexes
	 */
	public Region_Quartile(RADDACL_Cluster parent, List<Integer> inputIndexes)
	{
		this.parent = parent;
		this.inputIndexes = inputIndexes;
		this.table = new DistanceTable_Centroid(parent, this);
		this.table.generateDistanceTable();
	}
	/**
	 * 
	 * @param parent
	 * @param inputIndexes
	 * @param pcentroid
	 * @param pthreshold
	 */
	public Region_Quartile(RADDACL_Cluster parent, List<Integer> inputIndexes, Double pthreshold, Vector<Double> pcentroid)
	{
		this.parent = parent;
		this.inputIndexes = inputIndexes;
		this.pthreshold = pthreshold;
		this.pcentroid = pcentroid;
		this.table = new DistanceTable_Centroid(parent, this);
		this.table.generateDistanceTable();
	}
	@Override
	public Vector<Double> getCentroid() 
	{
		return this.table.getCentroid();
	}
	@Override
	public double getThreshold() 
	{
		return this.table.getThreshold();
	}
	@Override
	public boolean isPreCluster() 
	{
		try {
			if(inputIndexes.size() == 1)
			{
				return true;
			}
			else
			{
				return VectorMath.euclidianDistance(this.getCentroid(), this.pcentroid) >= this.getThreshold();
			}
		} catch (NullPointerException e) {
			return false;
		}
	}
}
